﻿using System;
using System.Collections.Generic;
using System.Text;

/*
 * Author:Conis
 * Date:
 * Description:JSON的根节点
 */
namespace Coins.Squirrel.Nodous.JSON
{
    public class JSONNodousRoot : JSONNodousNode, INodousRoot
    {
        private string returnString;

        #region 普通方法
        /// <summary>
        /// 创建根节点
        /// </summary>
        /// <param name="name">节点名称</param>
        public JSONNodousRoot(string name)
            : base(name)
        {
            this.container = new StringBuilder();
        }

        /// <summary>
        /// 创建前缀
        /// </summary>
        protected override void CreatePreifx()
        {
            this.container.Append("{");
        }

        /// <summary>
        /// 创建后缀
        /// </summary>
        protected override void CreateSuffix()
        {
            this.container.Append("}");
        }

        /// <summary>
        /// 创建JSON数据
        /// </summary>
        public new void Create()
        {
            //在创建的时候清空数据
            this.container.Remove(0, this.container.Length);
            base.Create();
            this.returnString = this.container.ToString();
        }

        /// <summary>
        /// 返回JSON数据
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.returnString;
        }
        #endregion
    }
}
